package com.weakteam.orderonline.adminconsole.gwt.client.domain;

import com.google.gwt.json.client.*;

/**
 * @author Nail
 */
public class Place {

    private Integer id;

    private String name;

    public Place() {}

    public Place(JSONObject obj) {
        this.set(obj);
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void set(JSONObject jsonObj) {
        JSONNumber jId = jsonObj.get("id").isNumber();
        if (jId != null) this.id = (int)jId.doubleValue();
        //ConsoleLog.getInstance().debug("id=" + id);

        JSONString jName = jsonObj.get("name").isString();
        if (jName != null) this.name = jName.stringValue();
        //ConsoleLog.getInstance().debug("name=" + name);
    }

    public JSONObject getJSON() {
        JSONObject jsonObject = new JSONObject();
        if (id != null) {
            jsonObject.put("id", new JSONNumber(this.id));
        } else {
            jsonObject.put("id", JSONNull.getInstance());
        }

        if (name != null) {
            jsonObject.put("name", new JSONString(this.name));
        } else {
            jsonObject.put("name", JSONNull.getInstance());
        }
        return jsonObject;
    }
}
